package com.assistant.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.assistant.config.properties.FileLocationProperties;
import com.assistant.dao.domain.SysOperLog;
import com.assistant.dubbo.consumer.DubboFacade;
import com.assistant.logic.SysOperLogic;
import com.assistant.util.JsonUtil;
import com.assistant.vo.resp.AjaxResult;
import com.chujie.api.facade.resp.FacadeResultDto;
import com.chujie.api.facade.resp.UserInfoResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = "/index" ,produces={"application/json;charset=UTF-8"})
public class IndexController {
    @Autowired
    private FileLocationProperties fileLocationProperties;
    @Autowired
    private DubboFacade dubboFacade;

    @Value("${dept.name:}")
    private  String deptName;

    @Autowired
    private SysOperLogic sysOperLogic;

    @GetMapping(value = "/user/info" )
    public AjaxResult userInfo(String phone) {
        log.info("fileLocationProperties={}",JsonUtil.toJson(fileLocationProperties.getLocations()));
        FacadeResultDto<UserInfoResp> userInfoRespFacadeResultDto = dubboFacade.getUserFacade().fetchUserInfoByPhone(phone);
        if (!userInfoRespFacadeResultDto.getCode().equals(FacadeResultDto.SUCCESS_CODE)){
            throw new RuntimeException(userInfoRespFacadeResultDto.getMsg());
        }
        log.info("获取用户信息:{}",JsonUtil.toJson(userInfoRespFacadeResultDto));
        return AjaxResult.success("ok",userInfoRespFacadeResultDto.getData());
    }
    @GetMapping(value = "/sys/oper/logs" )
    public AjaxResult sys_oper_logs(int current,int size) {
        IPage<SysOperLog> sysOperLogIPage = sysOperLogic.sysOperLogsPage(current, size);
        return AjaxResult.success("ok",sysOperLogIPage);
    }
}
